<?php
function carouselDetails($recipe){
	return $recipe['name'];
}

function getTags($recipe){
	$class = "";
	for($i=0; $i<count($recipe['tags']); $i++):
		$temp = split(" ",$recipe['tags'][$i]['name']);
		for($j=0; $j<count(temp); $j++)
			$class .=$temp[$j]." ";
	endfor;
	return $class;	
}

function getIngredients($recipe){
	$class = "";
	for($i=0; $i<count($recipe['ingredients']); $i++):
		$temp = split(" ",$recipe['ingredients'][$i]['ingredient']);
		for($j=0; $j<count(temp); $j++)
		$class .=$temp[$j]." ";
	endfor;
	return $class;
}

function getClasses($recipe){
	$name = explode(" ",$recipe['name']);
	$result = "";
	for($i=0; $i<count($name); $i++)
		$result .= $name[$i]." ";
	return $result." ".getTags($recipe)." ".getIngredients($recipe);	
}

function displayCarousel($recipes,$type,$header,$user_id){
?><h3><?php echo $header;?></h3><?php
$no_recipes = "No recipes to display.";
if($recipes):
	switch($type){
	case "user":
	
	$count = userRecipeCount($recipes, $user_id);
	if($count==0):
		echo $no_recipes;
		return;
	endif;
	?>
<div id="your" class="recipe_carousel">
<?php foreach($recipes as $recipe):?>
<?php if($recipe['author']==$user_id):?>
        <div class="thumbnail <?php echo getClasses($recipe);?>">
            <img alt="" src="php/photo.php?recipe_id=<?php echo $recipe['rid'];?>" /><br />
            <input type="hidden" value="<?php echo $recipe['rid'];?>" />
            <div class="recipe-details"><?php echo carouselDetails($recipe);?></div>
        </div>
<?php endif;?>
<?php endforeach;?>
</div><!-- carousel -->
    <?php
	break;
	case "favorites":
	?>
<div id="favorite_slider" class="recipe_carousel">
<?php foreach($recipes as $recipe):?>
        <div class="thumbnail <?php echo getClasses($favorite);?>">
            <img alt="" src="php/photo.php?recipe_id=<?php echo $recipe['rid'];?>" /><br />
            <input type="hidden" value="<?php echo $recipe['rid'];?>" />
            <div class="recipe-details"><?php echo carouselDetails($recipe);?></div>
        </div>
<?php endforeach;?>
</div><!-- carousel -->	
    <?php
	break;
	case "others":
		$count = userRecipeCount($recipes, $user_id);
		if((count($recipes)-$count)==0):
			echo $no_recipes;
			return;
		endif;
	?>
<div id="friend_public" class="recipe_carousel">
<?php foreach($recipes as $recipe):?>
<?php if($recipe['author']!=$user_id):?>
        <div class="thumbnail <?php echo getClasses($recipe);?>">
            <img alt="" src="php/photo.php?recipe_id=<?php echo $recipe['rid'];?>" /><br />
            <input type="hidden" value="<?php echo $recipe['rid'];?>" />
            <div class="recipe-details"><?php echo carouselDetails($recipe);?></div>
        </div>
<?php endif;?>
<?php endforeach;?>
</div><!-- carousel -->
<?php
	break;
	}
else:
	echo $no_recipes;
endif;
}

function userRecipeCount($recipes, $user_id){
	if(!$recipes)
		return 0;
	foreach($recipes as $recipe):
		if($recipe['author']==$user_id)
			$count++;
	endforeach;
	return $count;
}
?>